﻿package ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import main.Main;
import vo.salesManager.BookAddPanelVO;
import vo.salesManager.BookModifyPanelVO;
import vo.salesManager.CustomerAddPanelVO;

import components.MyButton;
import components.MyFrame;
import components.MyPanel;



public class BookAddPanel extends MyPanel{
	
	private MyButton logoutButton;
	private MyButton returnbackButton;
	
	private JScrollPane addbookpanelScrollPane;
	private JLabel pleaseaddbookLabel;
	private JLabel booknameaddLabel;
	private JTextField booknameaddField;
	private JLabel bookclassaddLabel;
	private JComboBox bookclassaddComboBox;
	private JLabel authoraddLabel;
	private JTextField authoraddField;
	private JLabel publisheraddLabel;
	private JTextField publisheraddField;
	private JLabel booknumaddLabel;
	private JTextField booknumaddTextField;
	private JLabel bookpriceaddLabel;
	private JTextField bookpriceaddTextField;
	private JLabel isbnLabel;
	private JTextField isbnField;
	private MyButton confirmaddbookButton;


	protected void initComponent() {
		BookAddPanelVO bapvo=null;
		try {
			bapvo = Main.getLogic().getBapvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
		logoutButton = new MyButton("注销");
		returnbackButton = new MyButton("返回");
		logoutButton.setBounds(MyFrame.WIDTH-80,0, 80, 20);
		returnbackButton.setBounds(MyFrame.WIDTH-160,0, 80, 20);
		this.add(logoutButton);
		this.add(returnbackButton);
		
		addbookpanelScrollPane = new JScrollPane(this);
		addbookpanelScrollPane.setBounds(300, 150, 500, 450);
		addbookpanelScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		pleaseaddbookLabel = new JLabel("请输入图书信息：");
		booknameaddLabel = new JLabel("图书名称：");
		booknameaddField = new JTextField();
		bookclassaddLabel = new JLabel("图书分类：");
		bookclassaddComboBox = new JComboBox(bapvo.getTypes());
		authoraddLabel = new JLabel("作者：");
		authoraddField = new JTextField();
		publisheraddLabel = new JLabel("出版商：");
		publisheraddField = new JTextField();
		booknumaddLabel = new JLabel("图书数量：");
		booknumaddTextField = new JTextField();
		bookpriceaddLabel = new JLabel("图书单价：");
		bookpriceaddTextField = new JTextField();
		confirmaddbookButton = new MyButton("添加");
		isbnLabel = new JLabel("ISBN：");
        isbnField = new JTextField();
		pleaseaddbookLabel.setBounds(10, 20, 120, 20);
	    booknameaddLabel.setBounds(20, 100, 80, 20);
	    booknameaddField.setBounds(100, 100, 150, 25);
	    bookclassaddLabel.setBounds(20, 140, 80, 20);
	    bookclassaddComboBox.setBounds(100, 140, 150, 25);
	    authoraddLabel.setBounds(20, 180, 80, 20);
	    authoraddField.setBounds(100, 180, 150, 25);
	    publisheraddLabel.setBounds(20, 220, 80, 20);
	    publisheraddField.setBounds(100,220, 150, 25);
	    booknumaddLabel.setBounds(20, 260, 80, 20);
	    booknumaddTextField.setBounds(100, 260, 150, 25);
	    bookpriceaddLabel.setBounds(20, 300, 80, 20);
	    bookpriceaddTextField.setBounds(100, 300, 150, 25);
	    isbnLabel.setBounds(20, 340, 80, 20);
		isbnField.setBounds(100, 340, 150, 25);
	    confirmaddbookButton.setBounds(330, 140, 100, 40);
	    this.add(pleaseaddbookLabel);
	    this.add(booknameaddLabel);
	    this.add(booknameaddField);
	    this.add(bookclassaddLabel);
	    this.add(bookclassaddComboBox);
	    this.add(authoraddLabel);
	    this.add(authoraddField);
	    this.add(publisheraddLabel);
	    this.add(publisheraddField);
	    this.add(booknumaddLabel);
	    this.add(booknumaddTextField);
	    this.add(bookpriceaddLabel);
	    this.add(bookpriceaddTextField);
	    this.add(confirmaddbookButton);
	    this.add(isbnField);
	    this.add(isbnLabel);
	    
	    logoutButton.setButtonAction("logout");
		returnbackButton.setButtonAction("toBookQuery");
		confirmaddbookButton.setButtonAction("addBook");
	}

	@Override
	protected void updateVO() {
		BookAddPanelVO bapvo = null;
		try {
			bapvo = Main.getLogic().getBapvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		bapvo.setBookName(booknameaddField.getText());
		bapvo.setType(bookclassaddComboBox.getSelectedIndex());
		bapvo.setAuthor(authoraddField.getText());
		bapvo.setPublisher(publisheraddField.getText());
		bapvo.setBooknum(booknumaddTextField.getText());
		bapvo.setBookprice(bookpriceaddTextField.getText());
		bapvo.setIsbn(isbnField.getText());
		try {
			Main.getLogic().setBapvo(bapvo);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

}
